﻿using System;
using System.Collections.Generic;
using System.Text;

using Mang24k99.Model.Dissertation;
using Castle.ActiveRecord;

namespace Mang24k99.Business.Dissertation
{
    public partial class BDissertationToFile
    {
        public static IList<MDissertationToFile> GetAllByWebID(string webID)
        {
            return MDissertationToFile.Find("DissertationID", webID);
        }

        /// <summary>
        /// 删除一个参考文件
        /// </summary>
        /// <param name="aFile"></param>
        /// <returns></returns>
        public static bool Delete(MDissertationToFile aFile)
        {
            try
            {
                aFile.BDeleted = 0;
                aFile.DeleteTime = DateTime.Now;
                aFile.UpdateAndFlush();
                return true;
            }
            catch { return false; }
        }

        /// <summary>
        /// 判断是否已经添加二十个专题
        /// </summary>
        /// <param name="dissID"></param>
        /// <param name="iCount"></param>
        /// <returns></returns>
        public static bool HavaEnoughReference(string dissID, int iCount)
        {
            try {
                using (new SessionScope())
                {
                    MDissertations aDis = MDissertations.Find(int.Parse(dissID));

                    IList<MDissertationToFile> mdiss = aDis.DissertationToFile;
                    if (mdiss != null && mdiss.Count >= iCount)
                        return true;
                    else
                        return false;
                }
            }
            catch { return false; }
        }
    }
}